<%@page contentType="text/html"%>
<%@ page language="java" import="util.*, java.sql.*, beans.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Purchased Items Info</title>
<head>
    <link href="astyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="absolute_title">Captain Hook's Store</div>
    <div class="absolute_title2"> 
        <h5>
            <%
            String username = (String)session.getAttribute("username");
            
            if(username==null) {
                out.println("Please <a href='login.jsp'>Login.</a>");
            }else {
            %>
            
            <b>Hi!<%= username%></b><br/>
            <a href="logout.jsp"> Click here to logout</a>
        </h5>
    </div>
    <div class="wrap">
        <div class="canvas">
            <div class="left_column">
                <div class="header_left">
                    <div class="header_leftrowone">&nbsp;</div>
                    <div class="header_leftrowtwo"><img src="../image/cpt_hook_banner1.jpg" width="123" height="87" /></div>
                    <div class="header_leftrowthree"></div>
                </div>
                <div class="leftnav">
                    <ul>
                        <li></li>
                    </ul>
                </div>
                <div>
                    <SCRIPT src="displayMyFlash1.js"></SCRIPT>
                </div>
            </div>
            <div class="right_column">
                <div class="header_right">
                    <div class="header_rightrowone">&nbsp;</div>
                    <div class="header_rightrowtwo">&nbsp;</div>
                    <div class="header_rightrowthree">
                        <ul class="topmenu">
                            <li><a title="Home" 
                                   href="index.jsp">Home</a> | </li>
                            <li><a title="Information" 
                                   href="companybackground.html">Information</a> |
                            <li><a title="Forum" 
                                   href="http://www.voy.com/206926/">Discussion Forum</a></li>
                        </ul>
                    </div>
                </div>
                <div class="content_wrapper">
                    <div class="content_left">
                        <h2>Payment Detail</h2>
                        <table width="700" border="0" align="center">
                            
                            <tr>
                                <td align="center" valign="top" id="content"><table width="700" border="1">
                                        <tr bgcolor="white">
                                            <td width="20">Payment ID</td>
                                            <td width="30">Item</td>
                                            <td width="40">Name</td>
                                            <td width="20">Quantity</td>
                                            <td width="30">Image</td>
                                        </tr>                    
                                        <%
                                        final String sPage = (String)request.getParameter("page");
                                        int page1 = 0; //<====
                                        
                                        if(util.Utilities.isValid(sPage)) {
                                            try {
                                                page1 = Integer.parseInt(sPage);
                                            } catch(Exception e) {
                                                
                                            }
                                        }
                                        String paymentID = "";
                                        ModelBean[] model = new ModelBean[0];
                                        try {
                                            paymentID = request.getParameter("paymentID");
                                            if(util.Utilities.isValid(paymentID)) {
                                                int payment = Integer.parseInt(paymentID);
                                                model = PaymentBean.getModels(payment);
                                            }else {
                                                paymentID= "";
                                                model = new ModelBean[0];
                                            }
                                        }catch(Exception e) {}
                                        
                                        final int k=page1;
                                        
                                        final int recordPerPage = 5;
                                        final int indexPerPage =10;
                                        final int count = model.length; //<=======
                                        final int indexCount = (int)Math.floor(count / (double)recordPerPage);
                                        if(page1 > indexCount) {
                                            page1 = 0;
                                        }
                                        
                                        try {
                                            
                                            
                                            for(int z=recordPerPage*page1; z<(page1+1)*recordPerPage; z++ ) {
                                                String itemID = model[z].getItemID();
                                                String itemName = model[z].getName();
                                                int quantity = model[z].getQuantity();
                                                String imageURL = model[z].getImageURL();
                                        %>
                                        
                                        <tr bgcolor="white">
                                        <td>
                                            <%=paymentID%>
                                        </td>
                                        <td>
                                            <%=itemID%>
                                        </td>
                                        <td>
                                            <%=itemName%>
                                        </td>
                                        <td>
                                            <%=quantity%>
                                        </td>
                                        <td><a href='ItemDetail.jsp?imageURL=<%=imageURL%>'><img src='../image/<%=imageURL%>' width="162" height="200" border="0"/></a>
                                        <input type='hidden' name='imageURL' value='<%=imageURL%>' />                      </td>
                                        <%
                                        
                                            }
                                        }catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                        %>
                                        
                                </table></td>
                            </tr>
                            <p>&nbsp;</p>
                            <div class="post_btm">
                            <%!                                
                            void printIndex(int k, int i, JspWriter out1) {
                                try {
                                    if (i==k) {
                                        out1.println("<b><a href='PaymentDetail.jsp?page="+i+"'>"+(i+1)+"</a></b>");
                                    }else {
                                        out1.println("<a href='PaymentDetail.jsp?page="+i+"'>"+(i+1)+"</a>");
                                    }
                                }catch(Exception e) {
                                    
                                }
                            }
                            
                            %>
                            
                            <tr>
                                <td align="center" valign="top" id="footer"><form method='get' action='PaymentDetail.jsp'>
                                        
                                        <%
                                        int nextValue = 5;
                                        int remain = count-(indexCount+page1);
                                        if (remain < indexPerPage) {
                                            nextValue = remain % indexPerPage;
                                        }
                                        if(k < 5) {
                                            for(int i=0; i<=indexCount&&i<indexPerPage; i++) {
                                                printIndex(k, i, out);
                                            }
                                        }else if(indexCount < indexPerPage) {
                                            for(int i=0; i<=indexCount; i++) {
                                                printIndex(k, i, out);
                                            }
                                        }else if(k >= indexCount-indexCount%indexPerPage -1) {
                                            int start = indexCount - indexPerPage;
                                            for(int y=0; y <indexPerPage; y++) {
                                                printIndex(k, y+start, out);
                                            }
                                        }else {
                                            for (int i=0; i<5; i++) {
                                                printIndex(k, page1-5+i, out);
                                            }
                                            for (int i=0; i< 5&& page1+i<indexCount; i++) {
                                                printIndex(k, page1+i, out);
                                            }
                                        }
                                        
                                        %>
                                        <input type='hidden' name='page' value='<%=k+1%>' />
                                        <input type='hidden' name='paymentID' value='<%=paymentID%>' />
                                        <input type = submit value='Next Page'/>
                                        
                                </form></td>
                            </tr>
                    </table>   </div>
                </div>
            </div>
            <%
            } %>
            <blockquote>
                <p>&nbsp;</p>
            </blockquote>
            <div class="footer">
                <ul class="basemenu">
                    <li></li>
                </ul>
                Designed by Captain Hook inc, all rights reserved. <br />
            </div>
        </div>
    </div>
    </div>
</body>
</html>
